'''管理员系统核心代码'''
from lib import common
from lib.common import login_input, auth
from interface import admin_iface

admin_func_menu = '''
========== 管理员系统 ==========
        1.登录
        2.注册管理员
        3.创建讲师
        4.创建班级
        5.创建课程
        6.创建学校
        q.退出输入【q】
   【注: 只有管理员可以注册管理员】
====================================
'''


def admin_login():
    username, password = login_input()
    msg = admin_iface.login(username=username, password=password)
    print(msg)


@auth('admin')
def admin_register():
    username, password = login_input()
    msg = admin_iface.register(username=username, password=password)
    print(msg)


@auth('admin')
def create_teacher():
    teacher_name = input('请输入讲师姓名:').strip()
    teacher_age = input('请输入讲师年龄:').strip()
    teacher_sex = input('请输入讲师性别【male/female/other】:').strip()
    teacher_username = input('请输入讲师登录用户名:').strip()
    teacher_pwd = input('请输入讲师登录密码:').strip()
    common.show_all_courses()
    teacher_course = input('请输入讲师教学课程:').strip()
    res = admin_iface.create_teacher(name=teacher_name, age=teacher_age, sex=teacher_sex, username=teacher_username,
                                     pwd=teacher_pwd, course=teacher_course)
    print(res)


@auth('admin')
def create_course():
    course_name = input('请输入课程名称:').strip()
    course_desc = input('请输入课程概要:').strip()
    common.show_schools()
    course2school = input('请输入绑定的学校:').strip()
    msg = admin_iface.create_course(course_name=course_name, course_desc=course_desc, course2school=course2school)
    print(msg)


@auth('admin')
def create_school():
    school_name = input('请输入学校名称:').strip()
    school_address = input('请输入学校地址:').strip()
    msg = admin_iface.create_school(school_name=school_name, school_address=school_address)
    print(msg)


admin_menu_dict = {
    '1': admin_login,
    '2': admin_register,
    '3': create_teacher,
    '4': create_course,
    '5': create_school
}


def main():
    while True:
        print(admin_func_menu)
        func_choice = input("请输入功能ID:").strip()
        if func_choice.upper() == 'Q':
            admin_iface.quit_system()
            print('【已退出管理员系统】')
            break
        elif func_choice not in admin_menu_dict:
            print('【功能ID有误】')
        else:
            admin_menu_dict[func_choice]()
